package br.com.emanuelvictor.architectureandroid.app1.util;

import java.util.Calendar;

import android.app.Activity;
import android.support.v4.app.Fragment;
import br.com.emanuelvictor.architectureandroid.app1.fragment.smartphone.PointMainFragmentSmartphone;
import br.com.emanuelvictor.architectureandroid.app1.fragment.tablet.PointMainFragmentTablet;
import br.com.emanuelvictor.architectureandroid.util.Variables;

public class PointVariables extends Variables {

	private static final long serialVersionUID = 1L;
	private HistoryPath history = HistoryPath.newInstance();
	private Integer tagViewPager = 0;
	private HistoryNavigation historyNavigation = HistoryNavigation
			.newInstance(Calendar.getInstance());
	private Class<?> fragmentClass;

	public PointVariables(Activity activity) {
		super(activity);
	}

	public HistoryPath getHistory() {
		return history;
	}

	public void setHistory(HistoryPath history) {
		this.history = history;
	}
	
	public void setFragmentClass(Class<?> fragmentClass){
		this.fragmentClass = fragmentClass;
	}

	@Override
	public Fragment getFragment() {
		try {
			return (Fragment) this.fragmentClass.newInstance(); 
		} catch (Exception e) {
			// TODO Aqui poderão haver várias outras verificações
			// COmo por exemplo: SE é landscape, se é 2.3.3 etc
			if (isTablet(activity.getResources())) {
				this.setFragmentClass(null);
				return new PointMainFragmentTablet();
			}
			this.setFragmentClass(null);
			return new PointMainFragmentSmartphone();
		}

	}

	public HistoryNavigation getHistoryNavigation() {
		return historyNavigation;
	}

	public void setHistoryNavigation(HistoryNavigation historyNavigation) {
		this.historyNavigation = historyNavigation;
	}

	public Integer getTagViewPager() {
		return tagViewPager;
	}

	public void setTagViewPager(Integer tagViewPager) {
		this.tagViewPager = tagViewPager;
	}

}
